/**
 * 系统菜单
 */
DC.front.CreateSysMenu = function() {
 		var file_toolbar = new Ext.Toolbar().add({
			text : 'File....',
			width : 50,
			menu : new DC.front.menu.FileMenu()
		}).render('sys_menu_file');
		
		var edit_toolbar = new Ext.Toolbar().add({
			text : 'Edit.....',
			width : 50,
			menu : new DC.front.menu.Edit()
		}).render('sys_menu_edit');
		
		var Project_toolbar = new Ext.Toolbar().add({
			text : 'Project',
			width : 50,
			menu : new DC.front.menu.Project()
		}).render('sys_menu_project');
		
		var team_toolbar = new Ext.Toolbar().add({
			text : 'Team....',
			width : 50,
			menu : new DC.front.menu.Team()
		}).render('sys_menu_team');
};


// 文件菜单的下级菜单 
DC.front.menu.FileMenu = function(config) {
	
	DC.front.menu.FileMenu.superclass.constructor.call(this, Ext.apply({
		id : 'file_menu',
		text: 'File...',
		allowOtherMenus : false, //不允许同时显示多个菜单
		width : 200,
		items : [{
			id : 'sys_menu_new_project',
			text : 'New Project',
			iconCls : 'new_project_icon',
			listeners : {
				click : function() {
					new DC.front.win.NewProjectWin().show();
				}
			}
		}, '-', {
			id : 'sys_menu_new_class',
			text : 'New Class',
			iconCls : 'class_obj_icon',
			disabled : true,
			listeners : {
				click : function() {
					var selectedNode = DC.obj.explorer_treePanel.getSelectionModel().getSelectedNode();
					var path = "";
					if (selectedNode && !selectedNode.isLeaf()) {
						var array = selectedNode.getPath().split('/');
						var srcNodeText = DC.obj.explorer_treePanel.getNodeById(array[3]).attributes.text;
						if (srcNodeText == "src") {
							var project_id = array[2];
							var project_name = DC.obj.explorer_treePanel.getNodeById(array[2]).attributes.text;
							for (var i = 4, len = array.length; i < len; i++) {
								path = path + DC.obj.explorer_treePanel.getNodeById(array[i]).attributes.text + ".";
							}
							path = path.substring(0, path.length - 1);
							new DC.front.win.CreateClassWin({
								project_id : project_id,
								project_name : project_name,
								package_name : path
							}).show();
						}
					}
				}
			}
		}, {
			id : 'sys_menu_new_file',
			text : 'New File',
			iconCls : 'new_file_icon',
			disabled : true,
			listeners : {
				click : function() {
					new  DC.front.win.NewFileWin({
						type : 'file'
					}).show();
				}
			}
		}, {
			id : 'sys_menu_new_folder',
			text : 'New Folder',
			iconCls : 'folder_add_icon',
			disabled : true,
			listeners : {
				click : function() {
					new  DC.front.win.NewFileWin({
						type : 'folder'
					}).show();
				}
			}
		}, '-', {
			id : 'sys_menu_import_file',
			text : 'UpLoad File...',
			iconCls : 'import_file_icon',
			disabled : true,
			listeners : {
				click : function() {
					var pathStr = DC.obj.explorer_treePanel.getSelectedNodePath();
					new DC.front.win.UploadFileWin({
						path : pathStr.substring(0, pathStr.length - 1)
					}).show();
				}
			}
		}, {
			id : 'sys_menu_download_file',
			text : 'Download File...',
			disabled : true,
			listeners : {
				click : function() {
					DC.action.SysAction.downloadFile();
				}
			}
		}, {
			id : 'sys_menu_download_zipped_file',
			text : 'Download Zipped File...',
			iconCls : 'download_icon',
			disabled : true,
			listeners : {
				click : function() {
					DC.action.SysAction.downloadZipFile(DC.url.DOWNLOAD_ZIPFILE);
				}
			}
		}, '-', {
			id : 'sys_save',
			text : 'Save',
			iconCls : 'save_icon',
			listeners : {
				click : function() {
					DC.action.SysAction.saveFile();
				}
			}
		}, {
			id : 'sys_save_as',
			text : 'Save All',
			iconCls : 'save_all_icon',
			listeners : {
				click : function() {
					DC.action.SysAction.saveAllOpenFile();
				}
			}
		}, '-', {
			id : 'sys_menu_rename',
			text : 'Rename...',
			iconCls : 'rename_icon',
			disabled : true,
			listeners : {
				click : function() {
					var selectedNode = DC.obj.explorer_treePanel.getSelectionModel().getSelectedNode();
					var path = DC.obj.explorer_treePanel.getSelectedNodePath();
					new DC.front.win.RenameFileWin({
						nodeId : selectedNode.attributes.id,
						depth : selectedNode.getDepth(),
						filePath : path.substring(0, path.length - 1),
						fileName : selectedNode.attributes.text
					}).show();
				}
			}
		}]
	}, config ||{}));
};

Ext.extend(DC.front.menu.FileMenu, Ext.menu.Menu, {
	
});

// 编辑菜单的下级菜单
DC.front.menu.Edit = function(config) {
	DC.front.menu.Edit.superclass.constructor.call(this, Ext.apply({
		id : 'edit_menu',
		allowOtherMenus: false,
		width : 200,
		items : [{
			id : 'sys_menu_undo',
			text : 'Undo',
			iconCls : 'undo_icon',
			listeners : {
				click : function() {
					var activeTab_id = DC.obj.editor_tabPanel.getActiveTab().getId();
					if (activeTab_id != 'editor_tabPanel_homePage') {
						var code_field = Ext.getCmp(activeTab_id + '_field');
						code_field.undo();
					}
				}
			}
		}, {
			id : 'sys_menu_redo',
			text : 'Redo',
			iconCls : 'redo_icon',
			listeners : {
				click : function() {
					var activeTab_id = DC.obj.editor_tabPanel.getActiveTab().getId();
					if (activeTab_id != 'editor_tabPanel_homePage') {
						var code_field = Ext.getCmp(activeTab_id + '_field');
						code_field.redo();
					}
				}
			}
		}, '-', {
			id : 'sys_copy',
			text : 'Copy',
			iconCls : 'copy_icon'
		}, {
			id : 'sys_paste',
			text : 'Paste',
			iconCls : 'paste_icon'
		}, {
			id : 'sys_cut',
			text : 'Cut',
			iconCls : 'cut_icon'
		}, '-', {
			id : 'sys_menu_delete',
			text : 'Delete',
			iconCls : 'delete_icon',
			disabled : true,
			listeners : {
				click : function() {
					DC.action.SysAction.deleteNode(DC.obj.explorer_treePanel.getSelectionModel().getSelectedNode());
				}
			}
		}]
	}, config ||{}));
};

Ext.extend(DC.front.menu.Edit, Ext.menu.Menu, {
	
});

// 新建菜单的下级菜单
DC.front.menu.Project = function(config) {
	DC.front.menu.Project.superclass.constructor.call(this, Ext.apply({
		id : 'project_menu',
		allowOtherMenus: false,
		width : 200,
		items : [{
			id : 'sys_menu_open_project',
			text : 'Open Project',
			iconCls : 'open_project_icon',
			listeners : {
				click : function() {
					new DC.front.ProjectGridWin().show();
				}
			}
		}, {
			id : 'sys_menu_close_project',
			text : 'Close Project',
			iconCls : 'close_project_icon',
			disabled : true,
			listeners : {
				click : function() {
					var selectedNode = DC.obj.explorer_treePanel.getSelectionModel().getSelectedNode();
					DC.action.SysAction.closeProject(selectedNode.attributes.id, selectedNode.attributes.text);
				}
			}
		}, '-', {
			id : 'sys_menu_build',
			text : 'Bulid...',
			iconCls : 'build_icon',
			disabled : true,
			listeners : {
				click : function() {
					new DC.action.SysAction.buildProject();
				}
			}
		}, {
			id : 'sys_menu_run',
			text : 'Run...',
			iconCls : '',
			disabled : true,
			listeners : {
				click : function() {
					new DC.action.SysAction.runProject();
				}
			}
		}, {
			id : 'sys_menu_download_and_build_project',
			text : 'Download And Build Project',
			disabled : true,
			listeners : {
				click : function() {
					DC.action.SysAction.downloadAndBuildProject();
				}
			}
		}]
	}, config ||{}));
};

Ext.extend(DC.front.menu.Project, Ext.menu.Menu, {
	
});

DC.front.menu.Team = function(config) {
	DC.front.menu.Team.superclass.constructor.call(this, Ext.apply({
		id : 'team_menu',
		allowOtherMenus: false,
		width : 200,
		items : [{
			id : 'sys_menu_create_site',
			text : 'Create Site',
			listeners : {
				click : function() {
					new DC.front.win.CreateSiteWin().show();
				}
			}
		}, {
			id : 'sys_menu_import',
			text : 'Import',
			listeners : {
				click : function() {
					new DC.front.win.ImportProjectWin().show();
				}
			}
		}, {
			id : 'sys_menu_update',
			text : 'Update'
		}, {
			id : 'sys_menu_commit',
			text : 'Commit'
		}, {
			id : 'sys_menu_checkout',
			text : 'CheckOut',
			listeners : {
				click : function() {
					new DC.front.win.CheckoutProjectWin().show();
				}
			}
		}]
	}, config ||{}));
};

Ext.extend(DC.front.menu.Team, Ext.menu.Menu, {
	
});